<pre>

import java.util.Map;

import org.junit.Test;

import bingosoft.components.base.helper.LogHelper;
import bingosoft.components.base.service.ResultPage;
import leap.webunit.WebTestBase;
import leap.webunit.client.THttpResponse;

/**
 * @author ${author}
 * @功能描述 ${table.tableComment}服务API测试类
 * @创建时间 ${date}
 */
public class ${table.capitalTableName}ControllerTest extends WebTestBase{

	/**
	 * ${table.tableComment}服务API URL地址
	 */
	protected static final String PATH = "/${table.humpTableName}";
	
	/**
	 * ${table.tableComment}业务服务接口
	 */
	protected ${table.capitalTableName}Service ${table.humpTableName}Service = new ${table.capitalTableName}Service();
	
	/**
	 * 测试分页查询${table.tableComment} - success
	 */
	@Test
	public void testPageQuery${table.capitalTableName}s() {
		THttpResponse response = get(PATH + "?page_size=5&page=2&t=1");
		response.assertContentNotEmpty().assertSuccess();

		ResultPage resultPage = response.decodeJson(ResultPage.class);
		LogHelper.println("resultPage", resultPage);
	}
	
	/**
	 * 测试创建${table.tableComment} - success
	 */
	@Test
	public void testCreate${table.capitalTableName}() {
		${table.capitalTableName}Form ${table.humpTableName}Form = ${table.capitalTableName}ServiceTest.build${table.capitalTableName}Form(1);
		THttpResponse response = postJson(PATH, ${table.humpTableName}Form);
		response.assertContentNotEmpty().assertSuccess();
		
		String message = response.getContent();
		LogHelper.println("message", message);
		assertEquals(message, this.buildMessage(${table.capitalTableName}Service.MESSAGE_CREATE_SUCCESS));
	}

	/**
	 * 测试修改${table.tableComment} - fail ID不存在
	 */
	@Test
	public void testUpdate${table.capitalTableName}_noExist() {
		String ${pkCol.columnName} = "null";
		
		${table.capitalTableName}Form ${table.humpTableName}Form = ${table.capitalTableName}ServiceTest.build${table.capitalTableName}Form(1);
		${table.humpTableName}Form.set${pkCol.capitalColumnName}(${pkCol.columnName});
		THttpResponse response = patchJson(PATH + "/" + ${pkCol.columnName}, ${table.humpTableName}Form);
		response.assertContentNotEmpty().assertBadRequest();
		
		Map&lt;String,Object&gt; result = response.decodeJsonMap();
		String message = result.get("message").toString();
		LogHelper.println("message", message);
		assertEquals(message, ${table.capitalTableName}Service.MESSAGE_GET_FAIL);
	}

	/**
	 * 测试修改${table.tableComment} - success
	 */
	@Test
	public void testUpdate${table.capitalTableName}() {
		// 获取存在的${table.tableComment}ID
		String ${pkCol.columnName} = ${table.capitalTableName}ServiceTest.getExist${pkCol.capitalColumnName}();
		
		${table.capitalTableName}Form ${table.humpTableName}Form = ${table.capitalTableName}ServiceTest.build${table.capitalTableName}Form(1);
		${table.humpTableName}Form.set${pkCol.capitalColumnName}(${pkCol.columnName});
		THttpResponse response = patchJson(PATH + "/" + ${pkCol.columnName}, ${table.humpTableName}Form);
		response.assertContentNotEmpty().assertSuccess();
		
		String message = response.getContent();
		LogHelper.println("message", message);
		assertEquals(message, this.buildMessage(${table.capitalTableName}Service.MESSAGE_UPDATE_SUCCESS));
	}

	/**
	 * 测试获取${table.tableComment} - fail ID不存在
	 */
	@Test
	public void testGet${table.capitalTableName}_noExist() {
		String ${pkCol.columnName} = "null";
		
		THttpResponse response = get(PATH + "/" + ${pkCol.columnName});
		response.assertContentNotEmpty().assertBadRequest();

		Map&lt;String,Object&gt; result = response.decodeJsonMap();
		String message = result.get("message").toString();
		LogHelper.println("message", message);
		assertEquals(message, ${table.capitalTableName}Service.MESSAGE_GET_FAIL);
	}
	
	/**
	 * 测试获取${table.tableComment} - success
	 */
	@Test
	public void testGet${table.capitalTableName}() {
		// 获取存在的${table.tableComment}ID
		String ${pkCol.columnName} = ${table.capitalTableName}ServiceTest.getExist${pkCol.capitalColumnName}();
		
		THttpResponse response = get(PATH + "/" + ${pkCol.columnName});
		response.assertContentNotEmpty().assertSuccess();

		${table.capitalTableName}Form ${table.humpTableName}Form = response.decodeJson(${table.capitalTableName}Form.class);
		LogHelper.println("${table.humpTableName}Form", ${table.humpTableName}Form);
	}

	/**
	 * 测试删除${table.tableComment} - fail ID不存在
	 */
	@Test
	public void testDelete${table.capitalTableName}_noExist() {
		String ${pkCol.columnName} = "null";
		
		THttpResponse response = delete(PATH + "/" + ${pkCol.columnName});
		response.assertContentNotEmpty().assertBadRequest();
		
		Map&lt;String,Object&gt; result = response.decodeJsonMap();
		String message = result.get("message").toString();
		LogHelper.println("message", message);
		assertEquals(message, ${table.capitalTableName}Service.MESSAGE_DELETE_FAIL);		
	}
	
	/**
	 * 测试删除${table.tableComment} - success
	 */
	@Test
	public void testDelete${table.capitalTableName}() {
		// 获取存在的${table.tableComment}ID
		String ${pkCol.columnName} = ${table.capitalTableName}ServiceTest.getExist${pkCol.capitalColumnName}();
		
		THttpResponse response = delete(PATH + "/" + ${pkCol.columnName});
		response.assertContentNotEmpty().assertSuccess();
		
		String message = response.getContent();
		LogHelper.println("message", message);
		assertEquals(message, this.buildMessage(${table.capitalTableName}Service.MESSAGE_DELETE_SUCCESS));		
	}
	
	protected Object buildMessage(String message) {
		return "\"" + message + "\"";
	}
}
</pre>
